package com.cy.model;

import com.cy.BasicModel;
import com.cy.ext.plugin.tablebind.TableBind;

import java.util.Date;
import java.util.List;

@TableBind(tableName="batch",pkName = "id")
public class Batch extends BasicModel<Batch> {
    public static final Batch dao = new Batch();
    public static final String SELECT_ALL = "`id`,`device_attr_id`,`batch_num`,`start_date`,`end_date`,`manufacturers`,`planned_production_num`,`type`,`status`,`firmware_version_id`,`remark`";

    public List<Batch> findByDeviceAttr(Long deviceAttrId) {
        return find("SELECT * FROM batch WHERE device_attr_id = ?", deviceAttrId);
    }

    public Batch findByBatchNum(String batchNum){
        return findFirst("SELECT * FROM batch WHERE batch_num = ?",batchNum);
    }

    public Shift getShiftBySerialNum(String serialNum){
        return Shift.dao.findFirst("SELECT s.* FROM shift s INNER JOIN shift_serial_num sn ON s.id = sn.shift_id WHERE s.batch_id = ? AND sn.start_num <= ? AND sn.end_num >= ?", getId(), serialNum, serialNum);
    }

    public Batch setId(Long id){
        return this.set("id", id);
    }

    public Long getId(){
        return this.get("id");
    }
        
    public Batch setDeviceAttrId(Long deviceAttrId){
        return this.set("device_attr_id",deviceAttrId);
    }

    public Long getDeviceAttrId(){
        return this.get("device_attr_id");
    }

    public DeviceAttr getDeviceAttr(){
        return DeviceAttr.dao.findById(getDeviceAttrId());
    }

    public Batch setBatchNum(String batchNum){
        return this.set("batch_num",batchNum);
    }

    public String getBatchNum(){
        return this.getStr("batch_num");
    }
        
    public Batch setStartDate(Date startDate){
        return this.set("start_date",startDate);
    }

    public Date getStartDate(){
        return this.get("start_date");
    }
        
    public Batch setEndDate(Date endDate){
        return this.set("end_date",endDate);
    }

    public Date getEndDate(){
        return this.get("end_date");
    }
        
    public Batch setManufacturers(String manufacturers){
        return this.set("manufacturers",manufacturers);
    }

    public String getManufacturers(){
        return this.getStr("manufacturers");
    }
        
    public Batch setPlannedProductionNum(Long plannedProductionNum){
        return this.set("planned_production_num", plannedProductionNum);
    }

    public Long getPlannedProductionNum(){
        return this.get("planned_production_num");
    }
        
    public Batch setType(Integer type){
        return this.set("type", type);
    }

    public Integer getType(){
        return this.get("type");
    }
        
    public Batch setStatus(Integer status){
        return this.set("status", status);
    }

    public Integer getStatus(){
        return this.get("status");
    }
        
    public Batch setFirmwareVersionId(Long firmwareVersionId){
        return this.set("firmware_version_id", firmwareVersionId);
    }

    public Long getFirmwareVersionId(){
        return this.get("firmware_version_id");
    }
        
    public Batch setRemark(String remark){
        return this.set("remark",remark);
    }

    public String getRemark(){
        return this.get("remark");
    }
}